home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10284 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.7 KB  |  107 lines

  1. Path: usenet.eel.ufl.edu!warwick!bham!bhamcs!news
  2. From: Ian Moody <I.J.Moody-CSAI93@cs.bham.ac.uk>
  3. Newsgroups: comp.lang.c++
  4. Subject: Nasty bus error using pure virtual functions
  5. Date: Thu, 07 Mar 1996 01:12:41 +0000
  6. Organization: University of Birmingham
  7. Message-ID: <313E3809.67F8@cs.bham.ac.uk>
  8. NNTP-Posting-Host: mother.cs.bham.ac.uk
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.0 (X11; I; SunOS 5.4 sun4m)
  13. CC: I.J.Moody-CSAI93@cs.bham.ac.uk
  14.  
  15. Hi,
  16.  
  17. I am getting a very nasty bus error in my code which I simply CANNOT
  18. get rid of.  I can usually cope OK with bus errors but this has me 
  19. completely stumped.  The program is being developed on a Sun network
  20. as part of my university final year project and I only have
  21. two weeks left to sort it out....(me thinks I left things a bit late) 
  22.  
  23. Here is an outline of the part of my proggy concerned (please ignore
  24. any obvious spelling mistakes and my strange way of implementing a
  25. linked list {:)
  26.  
  27.  
  28. struct LinkedListStruct
  29. {
  30.    void *item;
  31.    int type;
  32.    LinkedListStruct *next;
  33. };
  34.  
  35. class LinkedList
  36. {
  37.   protected:
  38.     LinkedList();
  39.     virtual int Compare(int,void*,void*) = 0;
  40.     int Find(LinkedListStruct*,LinkedListStruct*,void*);
  41.     int Remove(....);
  42.     ....
  43. };
  44.  
  45. int LinkedList::Find(LinkedListStruct *first,
  46.                     LinkedListStruct *last,
  47.                     void *data)
  48. {
  49.   ...
  50.   LinkedListStruct *current=first;    
  51.   while(current)
  52.    {
  53.      if(Compare(current->type,current->item,data)==0)
  54.       {
  55.         ...
  56.       }
  57.     current=current->next;
  58.    };
  59.   ...
  60. };
  61.  
  62. i.e. any class which inherits LinkedList MUST provide its own
  63. compare function.  The Find(...) function uses Compare(...) to
  64. see if there are any similar items already on the list.  arg is
  65. not important. 
  66. Now I have for example ...
  67.  
  68.  
  69. class FileLock : public LinkedList
  70. {
  71.   private:
  72.     LinkedListStruct *first;
  73.     LinkedListStruct *last;
  74.     int counter;
  75.  public:
  76.    FileLock();
  77.    ....
  78.    int FindLock(void*);
  79. };
  80.  
  81.  
  82. int FileLock::FindLock(void *stuff)
  83. {
  84.    ...
  85.    Find(first,last,stuff);
  86.    ...
  87. };
  88.  
  89. NOW, when I call FindLock(....)
  90. I get a BUS error on the line in LinkedList::Find(...) which tries
  91. to do the Compare(...), as far as I can tell it's somthing to do with
  92. the arguments I'm give it.  My other theory is that its something
  93. to do with having pure virtual functions?
  94.  
  95. This is all part of a multithreaded program, but I'm SURE that this
  96. has nothing to do with it because I still get the error even if I create
  97. some dummy variables and arguments within the LinkedList::Find(...)
  98. function and try to pass them to the Compare(..). 
  99.  
  100. I hope I haven't explained it too badly...
  101. Is there anywhere else I could post this as I really am getting a bit
  102. desperate now.
  103.  
  104. thanks,
  105.  
  106. Ian Moody,
  107.